//
//  CourseDetailViewController.m
//  TeacherNet
//
//  Created by slz on 2017/11/14.
//  Copyright © 2017年 bnsr. All rights reserved.
//

enum
{
    SliderButtonTypeDesc = 0,
    SliderButtonTypeCycle = 1 << 0,
    SliderButtonTypeComment = 2 << 0
};
typedef NSUInteger SliderButtonType;

#define kBannerHeight kScreenWidth * 0.5
#define kSignUpButtonHeight kTabbarHeight
#define kSliderHeight 40
#define kLeftMargin 15

@protocol CourseDetailSliderViewDelegate<NSObject>
- (void)sliderViewClickWithButtonType:(SliderButtonType)type;
@end

#import "CourseDetailViewController.h"
#import "CourseDetailDescView.h"
#import "CourseDetailCycleView.h"
#import "CourseDetailCommentView.h"
#import "CourseDetailDescModel.h"
#import "CourseCommentViewController.h"
#import "CouseSignUpViewController.h"
#import "NSDate+Addition.h"
#import "YWActionSheet.h"
#import "CourseSerciveViewController.h"
#import "UIImage+ImageEffects.h"


#define kLineColor [UIColor colorWithRGB:0xcdcdcd]

@interface CourseSliderButton : UIButton

@end
@implementation CourseSliderButton

+ (instancetype)initWithTitle:(NSString *)title target:(id)target andSel:(SEL)sel{
    CGFloat buttonWidth = (kScreenWidth - 80)/3;
    CGSize buttonSize = CGSizeMake(buttonWidth, 40);
    CourseSliderButton * button = [CourseSliderButton buttonWithType:UIButtonTypeCustom];
    button.size = buttonSize;
    button.titleLabel.fontSize = 15;
    [button setTitleColor:kDark_TextColor_Default forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    return button;
}

@end


@interface CourseDetailSliderView : UIView
@property (nonatomic,strong) CourseSliderButton *courseDescButton;
@property (nonatomic,strong) CourseSliderButton *courseCycleButton;
@property (nonatomic,strong) CourseSliderButton *courseCommentButton;
@property (nonatomic,strong) UIView *slider;
@property(nonatomic,weak) id <CourseDetailSliderViewDelegate> delegate;

@end
@implementation CourseDetailSliderView
- (instancetype)init
{
    self = [super init];
    if (self){
        self.backgroundColor = kLineColor_Gray_Default;
        _courseDescButton = [CourseSliderButton initWithTitle:@"简介" target:self andSel:@selector(changeAction:)];
        _courseDescButton.origin = CGPointMake(0, 0);
        _courseDescButton.tag = 0;
        [self addSubview:_courseDescButton];
        
        _courseCycleButton = [CourseSliderButton initWithTitle:@"课程" target:self andSel:@selector(changeAction:)];
        _courseCycleButton.origin = CGPointMake(_courseDescButton.right, 0);
        _courseCycleButton.tag = 1;
        [self addSubview:_courseCycleButton];
        
        _courseCommentButton = [CourseSliderButton initWithTitle:@"评论" target:self andSel:@selector(changeAction:)];
        _courseCommentButton.origin = CGPointMake(_courseCycleButton.right, 0);
        _courseCommentButton.tag = 2;
        [self addSubview:_courseCommentButton];
        
        
        CALayer * lineLayer = [CALayer new];
        lineLayer.size = CGSizeMake(1, 40);
        lineLayer.left = _courseCommentButton.right;
        lineLayer.top = 0;
        lineLayer.backgroundColor = kLineColor.CGColor;
        [self.layer addSublayer:lineLayer];
        
        CALayer * verLine = [CALayer new];
        verLine.size = CGSizeMake(kScreenWidth, 1);
        verLine.left = 0;
        verLine.bottom = 40;
        verLine.backgroundColor = kLineColor.CGColor;
        [self.layer addSublayer:verLine];
        
        _slider = [UIView new];
        [self addSubview:_slider];
        _slider.frame = CGRectMake(0, 36, _courseCommentButton.width, 4);
        _slider.backgroundColor = [UIColor blackColor];
    }
    return self;
}

- (void)changeAction:(CourseSliderButton *)button
{
    if ([_delegate respondsToSelector:@selector(sliderViewClickWithButtonType:)]){
        [_delegate sliderViewClickWithButtonType:button.tag];
    }
}

@end

@interface CourseDetailViewController ()<CourseDetailSliderViewDelegate,CourseDetailDescViewDelegate,YWActionSheetDelegate,UIScrollViewDelegate>
@property (strong, nonatomic) UIImageView *bannerImageView;
@property (nonatomic,strong) CourseDetailSliderView *sliderView;
@property (nonatomic,strong) CourseDetailDescView *descView;
@property (nonatomic,strong) CourseDetailCycleView *cycleView;
@property (nonatomic,strong) CourseDetailCommentView *commentView;
@property (strong, nonatomic) TTScrollView *scrollView;
@property (strong, nonatomic) UIView *navView;
@property (nonatomic,strong) UIButton *signUpButton;
@property(nonatomic,assign) SliderButtonType currentType;
@property (nonatomic,strong) TTScrollView *verScrollView;
@property(nonatomic,assign) BOOL scrollViewDidScrollToTop;//判断当前页面是否滑到顶部  从而判断子视图能否滚动  webview tableview


@property (nonatomic,strong) UILabel *courseNameLabel;
@property (nonatomic,strong) UILabel *courseSchool;
@property (nonatomic,strong) UILabel *teacherName;
@property (nonatomic,strong) UILabel *titleLabel;
/**
 是否报名 用于判断按钮是否需要报名请求
 */
@property(nonatomic,assign) BOOL isJoin;

/**
 back button
 */
@property (nonatomic,strong) UIButton *backButton;
@end

@implementation CourseDetailViewController
{
    id _responseObj;
    CourseDetailDescModel * _detailModel;
    TTClassListModel * _listModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.showNavigationBar = NO;
    
    _scrollView.delegate = self;
    _currentType = SliderButtonTypeDesc;
    
    [self setControllerTitle:self.courseId];

    [self creatSignUpButton];

    [self creatSubViews];
    
    [self requestData];
    
}

- (void)creatSubViews{
//    CGFloat descHeight =
    _scrollView = [TTScrollView new];
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.and.top.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view).offset(-kSignUpButtonHeight);
    }];
    
    _navView = [UIView new];
    _navView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_navView];
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.and.top.mas_equalTo(self.view);
        make.height.mas_equalTo(self.customNavigationHeight);
    }];
    
    _bannerImageView = [[UIImageView alloc]init];
    _bannerImageView.contentMode = UIViewContentModeScaleAspectFill;
    _bannerImageView.layer.masksToBounds = YES;
    [_scrollView addSubview:_bannerImageView];
    [_bannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(_scrollView);
        make.width.mas_equalTo(kScreenWidth);
        make.height.mas_equalTo(kBannerHeight);
    }];
  
    
    UIImageView * cover = [UIImageView new];
    cover.image = [UIImage imageNamed:@"note_edit_top_cover"];
    [_bannerImageView addSubview:cover];
    [cover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(_bannerImageView);
    }];
    
    
    _courseNameLabel = [UILabel new];
    _courseNameLabel.textColor = [UIColor whiteColor];
    _courseNameLabel.fontSize = kFont_Size_Middle_Title;
    [cover addSubview:_courseNameLabel];
    [_courseNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(cover.mas_left).offset(kLeftMargin);
        make.bottom.mas_equalTo(cover.mas_bottom).offset(-41);
        make.right.mas_equalTo(cover.mas_right).offset(-20);
    }];
    
    _courseSchool = [UILabel new];
    _courseSchool.textColor = [UIColor whiteColor];
    _courseSchool.fontSize = kFont_Size_Cotent_Nomal;
    [cover addSubview:_courseSchool];
    [_courseSchool mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(cover.mas_left).offset(kLeftMargin);
        make.bottom.mas_equalTo(cover.mas_bottom).offset(-17);
    }];
    
    
    
    _sliderView = [[CourseDetailSliderView alloc]init];
    _sliderView.delegate = self;
    [_scrollView addSubview:_sliderView];
    [_sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.mas_equalTo(_scrollView);
        make.top.mas_equalTo(_bannerImageView.mas_bottom);
        make.height.mas_equalTo(kSliderHeight);
    }];
    
    
    _scrollView.bounces = NO;
    if (kIOS11AVAILABLE){
        _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    CGFloat subViewHeight = kScreenHeight - kBannerHeight - kSliderHeight - kSignUpButtonHeight + (kBannerHeight - self.customNavigationHeight);

    _verScrollView = [TTScrollView new];
    _verScrollView.backgroundColor = [UIColor yellowColor];
    _verScrollView.pagingEnabled = YES;
    _verScrollView.scrollEnabled = NO;
    _verScrollView.bounces = NO;
    [_scrollView addSubview:_verScrollView];
    [_verScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_sliderView.mas_bottom);
        make.left.right.and.bottom.mas_equalTo(_scrollView);
        make.height.mas_equalTo(subViewHeight);
    }];
    
    
    _descView = [CourseDetailDescView new];
    _descView.webView.scrollView.scrollEnabled = NO;
    _descView.delegate = self;
    _cycleView = [CourseDetailCycleView new];
    _cycleView.tableView.scrollEnabled = NO;
    _commentView = [CourseDetailCommentView new];
    _commentView.tableView.scrollEnabled = NO;
    [_verScrollView addSubview:_descView];
    [_verScrollView addSubview:_cycleView];
    [_verScrollView addSubview:_commentView];

    
    [_descView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(_verScrollView);
        make.width.mas_equalTo(kScreenWidth);
        make.height.mas_equalTo(subViewHeight);
    }];
    

    [_cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_descView.mas_right);
        make.top.mas_equalTo(_verScrollView.top);
        make.width.mas_equalTo(kScreenWidth);
        make.height.mas_equalTo(subViewHeight);
//        make.bottom.mas_equalTo(_verScrollView.mas_bottom);
    }];
    
    [_commentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kScreenWidth, subViewHeight));
        make.left.mas_equalTo(_cycleView.mas_right);
        make.top.mas_equalTo(_cycleView.mas_top);
        make.right.mas_equalTo(_verScrollView.mas_right);
//        make.bottom.mas_equalTo(_verScrollView.mas_bottom);
    }];
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backButton setImage:[UIImage imageNamed:@"course_nav_back_arrow"] forState:UIControlStateNormal];
    [_backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [_navView addSubview:_backButton];
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_navView.mas_left).offset(18);
        make.centerY.mas_equalTo(_navView.mas_centerY).offset(IS_kiPhoneX ? 20 : 8);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
    
    _titleLabel = [UILabel new];
    _titleLabel.fontSize = 17;
    _titleLabel.hidden = YES;
    _titleLabel.textColor = kDark_TextColor_Default;
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [_navView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_navView.mas_right).offset(-63);
        make.left.mas_equalTo(_navView.mas_left).offset(63);
        make.centerY.mas_equalTo(_backButton.mas_centerY);
        make.centerX.mas_equalTo(_navView.mas_centerX);
    }];
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)creatSignUpButton
{
    _signUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_signUpButton setTitle:@"我要报名" forState:UIControlStateNormal];
    _signUpButton.titleLabel.fontSize = 18;
    [_signUpButton addTarget:self action:@selector(signUpAction) forControlEvents:UIControlEventTouchUpInside];
    [_signUpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _signUpButton.backgroundColor = kLoginGreenColor;
    [self.view addSubview:_signUpButton];
    [_signUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.and.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(kSignUpButtonHeight);
    }];
    
    CALayer * lineLayer = [CALayer new];
    lineLayer.size = CGSizeMake(kScreenWidth, 1);
    lineLayer.backgroundColor = kLineColor.CGColor;
    lineLayer.origin = CGPointMake(0, 0);
    [_signUpButton.layer addSublayer:lineLayer];
}



- (void)requestData{
    [BaseHttpTool get:kAPI_COURSE_DETAIL params:@{@"id":self.courseId,@"user_id":[MFWSdkEnvironment sharedInstance].userInfo.uid} success:^(id responseObj) {
        MFWJson * json = [MFWJson jsonWithObject:responseObj];
        NSDictionary * jsonDict = [[json jsonForKey:@"courseView"] toDic];
        _isJoin = [json booleanValueForKey:@"isJoin"];
        _detailModel = [CourseDetailDescModel yy_modelWithDictionary:jsonDict];
        [_descView loadUrl:_detailModel.courseDescUrl];
        NSURL * imageURl = [NSURL URLWithString:kAPI_IMAGE_HOST(_detailModel.courseBanner)];
        
        @weakify(self);
        [_bannerImageView sd_setImageWithURL:imageURl randomPlaceHolder:YES comepletion:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if (image){
                image = [image applyLightEffect];
                weak_self.bannerImageView.image = image;
            }
        }];
        
        [_descView updateWithModel:_detailModel];
        _courseSchool.text = _detailModel.courseScool;
        _courseNameLabel.text = _detailModel.courseName;
        _titleLabel.text = _detailModel.courseName;
        [self updateJoinState];
    } failure:^(NSError *error) {
        [self.view showTip:error.localizedDescription];
    }];
    
    [BaseHttpTool get:kAPI_COURSE_DETAIL_CYCLE params:@{@"id":self.courseId} success:^(id responseObj) {
        NSArray * arr = [[[MFWJson jsonWithObject:responseObj] jsonForKey:@"courseHourView"] toArray];
        if (!arr || arr.count == 0) return;
        [_cycleView updateWithModelArray:arr];
    } failure:^(NSError *error) {
        [self.view showTip:error.localizedDescription];
    }];
    
    [BaseHttpTool get:kAPI_COURSE_DETAIL_COMMENT  params:@{@"id":self.courseId} success:^(id responseObj) {
        _responseObj = responseObj;
        [_commentView updateWithPageObj:responseObj];
        
    } failure:^(NSError *error) {
        [self.view showTip:error.localizedDescription];
    }];
}

- (void)updateJoinState
{
    if (_isJoin){
        [_signUpButton setTitle:@"继续学习" forState:UIControlStateNormal];
    }else
    {
        [_signUpButton setTitle:@"我要报名" forState:UIControlStateNormal];
    }
}

- (void)signUpAction{
    
//    if (_currentType == 2){
//        if (!_responseObj)
//        {
//            [self.view showTip:@"网络错误~"];
//            return;
//        }
//        NSDictionary * dict = [[MFWJson jsonWithObject:_responseObj] toDic];
//        CourseCommentPageModel * pageModel = [CourseCommentPageModel yy_modelWithDictionary:dict];
//        CourseCommentViewController * commentController = [CourseCommentViewController new];
//        commentController.commentList = pageModel.quickComment;
//        [self.navigationController pushViewController:commentController animated:YES];
//    }else
    {
        if (!self.courseId || self.courseId.length == 0)
        {
            [self.view showTip:@"网络错误~" completion:NULL];
        }
        [self signUpRequestCompletion:^(BOOL signResult, NSString *requestResult) {
            if (signResult){
                CouseSignUpViewController * signUpController = [[CouseSignUpViewController alloc]init];
                signUpController.couseId = self.courseId;
                signUpController.courseTitle = _detailModel.courseName;
                signUpController.classId = _detailModel.classId;
                [self.navigationController pushViewController:signUpController animated:YES];
            }else
            {
                [self.view showTip:requestResult];
            }
        }];
    }
}

- (void)signUpRequestCompletion:(void(^)(BOOL signResult,NSString * requestResult))completion
{
    if (!_listModel || !_listModel.classList || _listModel.classList.count == 0){
        [self.view showTip:@"暂无班级，敬请期待~"];
        return;
    }
    if (![NSDate isEarlierThanTimeString:_descView.selectBackView.classModel.classSignUpLastTime]){
        if (completion){
            completion(NO,@"截止时间已过，敬请期待下次开班~");
        }
        return;
    }
    if (!self.courseId || self.courseId.length == 0 || !_detailModel.classId || _detailModel.classId.length ==0)
    {
        [self.view showTip:@"网络错误~" completion:NULL];
    }
    if (_isJoin){
        CouseSignUpViewController * signUpController = [[CouseSignUpViewController alloc]init];
        signUpController.couseId = self.courseId;
        signUpController.courseTitle = _detailModel.courseName;
        signUpController.classId = _detailModel.classId;
        [self.navigationController pushViewController:signUpController animated:YES];
    }else{
        [SVProgressHUD showWithStatus:@"报名中~"];
        [BaseHttpTool get:kAPI_COURSE_DETAIL_SIGNUP params:@{@"class_id":_detailModel.classId,@"user_id":[MFWSdkEnvironment sharedInstance].userInfo.uid} success:^(id responseObj) {
            [SVProgressHUD dismiss];
            completion(YES,@"");
        } failure:^(NSError *error) {
            [SVProgressHUD dismiss];
            [self.view showTip:error.localizedDescription];
        }];
    }
}

- (void)requestWithCourseId:(NSString *)courseId comletion:(void(^)(TTClassListModel * model))comletion
{
    [SVProgressHUD showWithStatus:@"获取中..."];
    [BaseHttpTool get:kAPI_COURSE_DETAIL_CLASS_LIST params:@{@"id":courseId} success:^(id responseObj) {
        [SVProgressHUD dismiss];
        TTClassListModel * classList = [TTClassListModel yy_modelWithDictionary:responseObj];
        _listModel = classList;
        if(classList)
        {
            comletion(classList);
        }
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self.view showTip:error.localizedDescription];
    }];
}

#pragma  mark - UIScrollViewDelaget

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offsetY = scrollView.contentOffset.y;
    NSInteger bannerHieght = floorf(kBannerHeight) - self.customNavigationHeight;

    
    CGFloat height = scrollView.frame.size.height;
    CGFloat contentOffsetY = scrollView.contentOffset.y;
    CGFloat bottomOffset = scrollView.contentSize.height - contentOffsetY;
    if (bottomOffset <= height)
    {
        //在最底部
        self.scrollViewDidScrollToTop = YES;
        _cycleView.tableView.scrollEnabled  =YES;
        _descView.webView.scrollView.scrollEnabled = YES;
        _commentView.tableView.scrollEnabled = YES;
        
    }
    else
    {
        self.scrollViewDidScrollToTop = NO;
        _cycleView.tableView.scrollEnabled = NO;
        _descView.webView.scrollView.scrollEnabled = NO;
        _commentView.tableView.scrollEnabled = NO;
    }
    
    if (offsetY >= bannerHieght){
        [UIView animateWithDuration:0.3 animations:^{
            _navView.backgroundColor = [UIColor whiteColor];
            _titleLabel.hidden = NO;
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            _navView.backgroundColor = [UIColor clearColor];
            _titleLabel.hidden = YES;
        }];
    }
    
}

#pragma mark - CourseDetailSliderViewDelegate

-(void)sliderViewClickWithButtonType:(SliderButtonType)type{
    if (type == _currentType) return;
    _currentType = type;
    CGFloat buttonWidth = (kScreenWidth - 80)/3;
    [UIView animateWithDuration:.3 animations:^{
        _sliderView.slider.left = type * buttonWidth;
    }];
    NSInteger contentOffsetX = type * kScreenWidth;
    CGPoint contentOffset = CGPointMake(contentOffsetX, 0);
    [UIView animateWithDuration:.3 animations:^{
        _verScrollView.contentOffset = contentOffset;
    }];
}

#pragma mark -

-(void)viewClickWithService
{
    CourseSerciveViewController * controller = [CourseSerciveViewController new];
    [self.navigationController pushViewController:controller animated:YES];
}

-(void)viewClickWithSelectClassId:(NSString *)selectId
{
    if (_listModel == nil){
        [self requestWithCourseId:self.courseId comletion:^(TTClassListModel *model) {
            YWActionSheet * sheet = [[YWActionSheet alloc]initWithlist:model.classList height:0 andCancelBtn:@"取消"];
            sheet.delegate =self;
            [sheet showinView:self.navigationController.view];
        }];
    }else
    {
            YWActionSheet * sheet = [[YWActionSheet alloc]initWithlist:_listModel.classList height:0 andCancelBtn:@"取消"];
            sheet.delegate =self;
            [sheet showinView:self.navigationController.view];
    }
}

-(void)actionSheetClickedAtIndex:(NSInteger)index andActionSheet:(YWActionSheet *)actionSheet
{
    
    TTClassModel * model = actionSheet.titleList[index];
    [self refreshWithClassID:model.classId];
    //todo 选择班级  显示班级名称 截止日期
}

- (void)refreshWithClassID:(NSString *)classID
{
    [SVProgressHUD showWithStatus:@""];
    [BaseHttpTool get:kAPI_COURSE_DETAIL params:@{@"id":self.courseId,@"user_id":[MFWSdkEnvironment sharedInstance].userInfo.uid,@"class_id":classID} success:^(id responseObj) {
        [SVProgressHUD dismiss];
        MFWJson * json = [MFWJson jsonWithObject:responseObj];
        NSDictionary * jsonDict = [[json jsonForKey:@"courseView"] toDic];
        _isJoin = [json booleanValueForKey:@"isJoin"];
        _detailModel = [CourseDetailDescModel yy_modelWithDictionary:jsonDict];
        [_descView loadUrl:_detailModel.courseDescUrl];
        NSURL * imageURl = [NSURL URLWithString:kAPI_IMAGE_HOST(_detailModel.courseBanner)];
        
        @weakify(self);
        [_bannerImageView sd_setImageWithURL:imageURl randomPlaceHolder:YES comepletion:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if (image){
                image = [image applyLightEffect];
                weak_self.bannerImageView.image = image;
            }
        }];
        
        
        [_descView updateWithModel:_detailModel];
        _courseSchool.text = _detailModel.courseScool;
        _courseNameLabel.text = _detailModel.courseName;
        _titleLabel.text = _detailModel.courseName;
        [self updateJoinState];
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self.view showTip:error.localizedDescription];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
